﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Core;

namespace Web.Controllers
{
    public class msgController : JsonController
    {
        //
        // GET: /msg/

        public ActionResult getNoticeList(int start, int limit)
        {
            return Json(msg.getNoticeList(start, limit));
        }

        [OnlyGod]
        public ActionResult deleteNotice(int nid)
        {
            return Json(msg.deleteNotice(nid));
        }

        [Myself]
        public ActionResult getMsgList(string username, int start, int limit)
        {
            return Json(msg.getMsgList(start, limit, username));
        }

        [NeedLogon]
        public ActionResult deleteMsg(int mid)
        {
            return Json(msg.deleteMsg(mid, Certify.username, Certify.god));
        }

        [Myself]
        public ActionResult cleanMsgBox(string username)
        {
            return Json(msg.cleanMsgBox(username));
        }

        [NeedLogon]
        public ActionResult inquiryNewMsg()
        {
            return Json(msg.inquiryNewMsg(Certify.username));
        }

        [NeedLogon]
        public ActionResult getMsg(int mid)
        {
            return Json(msg.getMsg(mid, Certify.username, Certify.god));
        }

        [ValidateInput(false)]
        [NeedLogon]
        [NeedOpenSendMsg]
        [ParamsNoEmpty]
        public ActionResult sendMsg(string to, string title, string content)
        {
            CheckHtmlWhite(content);
            return Json(msg.sendMsg(Certify.username, to, title, content));
        }

        public ActionResult getNotice(int nid)
        {
            return Json(msg.getNotice(nid));
        }

        [ValidateInput(false)]
        [OnlyGod]
        public ActionResult addOrEditNotice(int? nid, string title, string color, string content)
        {
            CheckEmpty(title, color);
            CheckHtmlWhite(content);
            return Json(msg.addOrEditNotice(nid, title, color, content));
        }

        [NeedOpenDiscuss]
        public ActionResult getDiscussTree(int? pid, int? did)
        {
            CheckNull(pid ?? did);
            return Json(msg.getDiscussTree(pid, did));
        }

        [OnlyGod]
        public ActionResult deleteDiscuss(int did)
        {
            return Json(msg.deleteDiscuss(did));
        }

        [NeedOpenDiscuss]
        public ActionResult getDiscuss(int did)
        {
            return Json(msg.getDiscuss(did));
        }

        [ValidateInput(false)]
        [NeedLogon]
        [NeedOpenSendDiscuss]
        public ActionResult addOrEditDiscuss(int? did, int? parentDid, int? pid, string title, string content)
        {
            CheckNull(pid ?? did);
            CheckEmpty(title);
            CheckHtmlWhite(content);
            return Json(msg.addOrEditDiscuss(did, parentDid, pid, Certify.username, title, content, functional.stripHtml(content).Trim().Length));
        }

        [NeedOpenDiscuss]
        public ActionResult getDiscussCount(int pid)
        {
            return Json(msg.getDiscussCount(pid));
        }

		[NeedLogon]
		[NeedOpenDiscuss]
		public ActionResult getDiscussList(int start, int limit)
		{
			return Json(msg.getDiscussList(start, limit, Certify.god));
		}
    }
}
